<template>
  <el-dialog :title="this.childtype" v-bind="dialogProps" :before-close="handleClose" :close-on-click-modal="false"
             :destroy-on-close="true"
             v-dialogDrag>
    <el-form ref="form" :rules="rules" :model="formEvent" label-width="125px" :size="size" :disabled="isDisabled">
      <el-row :gutter="16">
        <!-- 通过调整lg的大�?  12 24/3=12 会变为一�?3�? -->
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="24">
          <el-form-item label="巡视名称" prop="taskName">
            <el-input v-model="formEvent.taskName" placeholder="会自动生成,请填写其他选项" clearable type="textarea"
                      :rows="1"
                      @input="getTaskName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="8" :md="8" :lg="12" :xl="8">
          <el-form-item label="单位名称" prop="maintainUnitNo">
            <el-select v-model="formEvent.maintainUnitNo" placeholder="请选择单位" clearable @change="deptNoChange">
              <el-option v-for="item in OptionData.OptionData_deptNo" :key="item.value" :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="8" :md="8" :lg="12" :xl="8">
          <el-form-item label="能源站名称" prop="patrolRoomNo">
            <el-select v-model="formEvent.patrolRoomNo" placeholder="请选择能源站" clearable @change="deptNoChangeRoom">
              <el-option v-for="item in OptionData.OptionData_patrolRoomName" :key="item.value" :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="8" :md="8" :lg="12" :xl="8">
          <el-form-item label="巡视对象名称" prop="patrolTargetNames">
            <!-- <el-button  icon="fa fa-ellipsis-h" @click="inventoryClick"></el-button>  -->
            <el-input placeholder="--:--" v-model="formEvent.patrolTargetNames" class="input-with-select">
              <el-button slot="append" type="info" :disabled="btnDisabled" @click="inventoryClick">选择</el-button>
              <el-checkbox slot="append" v-model="formEvent.equipAllSelect" :true-label="1" :false-label="0"
                           style="margin-left:20px;" @change="changeSelect"></el-checkbox>
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :xs="24" :sm="8" :md="8" :lg="24" :xl="12">
          <el-form-item label="巡视类型" prop="patrolTypeNo">
            <el-select v-model="formEvent.patrolTypeNo" placeholder="请选择巡视类型" clearable
                       @change="taskTypeNoChange">
              <el-option v-for="item in OptionData.OptionData_taskTypeNo" :key="item.value" :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :xs="24" :sm="8" :md="8" :lg="12" :xl="8">
          <el-form-item label="巡视周期" prop="period" v-if="periodShow">
            <el-input v-if="formEvent.patrolTypeNo == '1'" v-model="formEvent.period" placeholder="请输入周期"
                      clearable></el-input>

          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="8" :md="8" :lg="12" :xl="8">
          <el-form-item label="周期结束时间" prop="periodEndTime" v-if="periodShow">
            <el-date-picker v-model="formEvent.periodEndTime" type="datetime" style="width:100%" placeholder="年/月/日"
                            format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="8" :md="8" :lg="12" :xl="8">
          <el-form-item label="计划开始时间" prop="planStartTime">
            <el-date-picker v-model="formEvent.planStartTime" type="datetime" style="width:100%"
                            placeholder="请选择计划开始时间"
                            format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
                            :picker-options="pickerOptions">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="8" :md="8" :lg="12" :xl="8">
          <el-form-item label="计划结束时间" prop="planEndTime">
            <el-date-picker v-model="formEvent.planEndTime" type="datetime" style="width:100%"
                            placeholder="请选择计划结束时间"
                            format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
                            :picker-options="pickerOptions" @change="handlePlanEndTime">
            </el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <el-form-item label="巡视内容" prop="patrolDescription">
            <el-input v-model="formEvent.patrolDescription" placeholder="请选择巡视内容" clearable
                      type="textarea"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <el-form-item label="备注">
            <el-input v-model="formEvent.remark" placeholder="请填写备注" clearable type="textarea"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <el-form-item label="是否检查机房卫生" prop="clean">
            <el-switch v-model="clean" active-color="#0e867f" inactive-color="#ff4949" @change="switchChange">
            </el-switch>

          </el-form-item>
        </el-col> -->
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
          <el-form-item label="创建人" prop="creator">
            <el-input v-model="formEvent.creator" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
          <el-form-item label="创建时间" prop="creatTime">
            <el-date-picker v-model="formEvent.creatTime" disabled type="datetime" style="width:100%"
                            format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 主键是不可以编辑的，不可查看�? -->
      <el-input v-model="formEvent.id" v-show="false"></el-input>

      <div>
        <h3 style="color:#009688;">巡视设备列表</h3>
      </div>
      <div style="width:100%;height:2px;background:#009688;margin-bottom: 10px;"></div>
      <el-button v-if="!isDisabled" icon="fa fa-trash-o" type="primary" size="small"
                 @click="handleDelete">删除
      </el-button>
      <vxe-table border stripe ref="selectedEquip" height="250" :data="entityList">
        <vxe-column type="seq" title="序号" width="60" align="center"></vxe-column>
        <vxe-column type="checkbox" width="60" align="center"></vxe-column>
        <vxe-column field="gldwmc" title="单位" align="center" minWidth="150"></vxe-column>
        <vxe-column field="gldwmc" title="班组名称" align="center" minWidth="150"></vxe-column>
        <vxe-column field="ccbm" title="出厂编码" align="center" minWidth="150"></vxe-column>
        <vxe-column field="equipName" title="设备名称" align="center" minWidth="150"></vxe-column>
        <vxe-column field="equipTypeName" title="设备类型" align="center" minWidth="150"></vxe-column>
      </vxe-table>
      <vxe-pager perfect size="mini" :current-page="list.pageNo" :page-size="list.pageSize" :page-sizes="list.pageSizes"
                 :total="list.total" :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
                 @page-change="handlePageChange" v-show="pagerShow">
      </vxe-pager>

      <selectEquipment ref="selectEquipment" :OptionData_stockType="OptionData.OptionData_stockType"
                       @onSelectEquips="onSelectEquips"></selectEquipment>
    </el-form>
    <span slot="footer" class="dialog-footer" v-show="!isDisabled">
      <el-button @click="handleCancel()" size="medium" icon="fa fa-minus-square-o">取消</el-button>
      <el-button type="primary" @click="handleSubmit()" size="medium" icon="fa fa-save (alias)">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import selectEquipment from "./selectEquipment";
import {FormEvent} from "../model/preparationTask-form.js";
import {formModel, GridEvent} from '../model/preparationTask-table'
import {reactive} from "vue";
import {preparationTask} from '@/api/patrol/preparationTask.js'
import {CommonApi} from '@/api/equip/CommonApi.js'
import moment from "moment";
import {getInfo} from "@/api/login";
import {listDept} from "@/api/system/dept";

export default {
  components: {selectEquipment},
  name: "preparationTaskForm",
  props: ['infoType'],


  data() {
    return {
      childtype: '',
      entityList: [],
      clean: false,
      dialogProps: {
        visible: false,

        width: "70%",
        top: "5px",
      },
      size: "small",
      formEvent: reactive(FormEvent).form,
      // rules: reactive(FormEvent).rules,
      periodShow: false,
      taskNoShow: false,
      btnDisabled: false,
      OptionData: {
        OptionData_warehouseNo: [],
        OptionData_stockType: [],
        OptionData_deptNo: GridEvent.OptionData_gldw,
        OptionData_teamNo: [],
        OptionData_taskTypeNo: GridEvent.OptionData_taskTypeNo,
        OptionData_personNo: [{label: 'zyn', value: '1111'}],
        OptionData_sblxmc: [{label: 'zyn', value: '1111'}],
        OptionData_patrolRoomName: [],//巡视机房
      },
      list: {
        data: [],
        pageNo: 1,
        pageSize: 10,
        pageSizes: [10, 20, 50, 100],
        total: 0,
      },
      pagerShow: false,
      isEdit: false,
      isDisabled: false,
      row: {},
      pickerOptions: {
        disabledDate(date) {
          return date.getTime() < Date.now() - 8.64e7 //8.64e7可以选择当前日期

        }
      }


    };
  },
  watch: {
    'infoType'(val) {
      this.childtype = val
    },
    'formEvent.patrolRoomNo'(val) {
      if (val !== '') {
        if (!this.isEdit) { //编辑情况下，不做修改
          this.setTestTaskName()
        }
      }

    },
    'formEvent.maintainUnitName'(val) {
      if (val !== '') {
        if (!this.isEdit) { //编辑情况下，不做修改
          this.setTestTaskName()
        }
      }
    },
    'formEvent.patrolTypeNo'(val) {
      if (val !== '') {
        if (!this.isEdit) { //编辑情况下，不做修改
          this.setTestTaskName()
        }
      }
    },

  },
  computed: {
    rules() {
      const obj = {
        taskName: "",//巡视工单名称
        maintainUnitNo: '',//单位
        patrolRoomName: "",//巡视机房
        patrolRoomNo: "",//巡视机房
        // stockTypeName: "",//巡视对象名称
        patrolTypeName: "",//巡视类型
        patrolTypeNo: "",//巡视类型编码
        period: "",//周期
        // sblxmc:"",//电周期
        periodEndTime: "",//周期结束时间
        planStartTime: "",//计划开始时间
        planEndTime: "",//计划结束时间
        patrolDescription: "",//巡视内容


        patrolTargetNames: ""//巡视对象

      }
      const fields = Object.keys(obj)
      const rules = {}
      fields.forEach(d => {
        if (d == 'creator' || d == 'creatTime' || d == 'machineSanitation') {
          return

        } else {

          rules[d] = [
            {required: true, message: '不能为空',}
          ]
        }

      })

      rules.planEndTime = [
        {required: true, message: '不能为空'},
        {validator: this.validationPart1, trigger: ['blur', 'change']}

      ]
      rules.periodEndTime = [
        {required: true, message: '不能为空'},
        {validator: this.validationPart2, trigger: ['blur', 'change']}

      ]
      return rules
    }
  },
  mounted() {
    this.childtype = this.infoType
  },
  methods: {
    switchChange() {
      this.formEvent.isClean = this.clean ? '1' : '0'
    },
    inspecTionChange(label) {
      console.log(label)
    },
    validationPart1(rule, value, callback) {

      if (this.formEvent.planStartTime < this.formEvent.planEndTime) {
        callback()
      } else {
        callback(new Error('结束时间必须大于开始时间'))
      }
    },
    validationPart2(rule, value, callback) {

      if (this.formEvent.periodEndTime > this.formEvent.planEndTime) {
        callback()
      } else {
        callback(new Error('周期结束时间必须大于结束时间'))
      }
    },
    validationSpace(rule, value, callback) {
      if (this.formEvent.patrolDescription.trim().length !== 0) {
        callback()
      } else {
        callback(new Error('不能输入空格'))
      }
    },
    showDialog(isEdit, row, isDisabled) {
      this.isEdit = isEdit || false
      this.isDisabled = isDisabled || false
      this.row = row || {}
      this.OptionData.OptionData_deptNo = GridEvent.OptionData_gldw
      this.getOptionData_stockType()
      this.getOptionData_taskTypeNo()
      this.getOptionData_taskTypeTime()
      this.getOptionData_warehouseNo()
      if (isEdit) {
        this.initData()
        this.pagerShow = true
        this.dialogProps.title = '编辑巡视工单'
      } else {
        if (isDisabled) {
          this.dialogProps.title = '新增巡视工单'
          this.initData();
          this.isDisabled = true
        } else {
          this.dialogProps.title = '新增巡视工单'
          this.list.data = []
          this.entityList = []
          preparationTask.gettaskNo().then(res => {
            this.formEvent.taskNo = res.data
          })
          getInfo().then(res => {
            this.formEvent.creator = res.user.nickName
            this.formEvent.creatorBm = res.user.userId

            this.formEvent.creatTime = moment().format("YYYY-MM-DD HH:mm:ss")
          })
          this.isDisabled = false
        }
      }
      this.dialogProps.visible = true
    },
    getOptionData_stockType() {
      let data = []
      preparationTask.queryDictDatasb({
        id: "",
        isLeaf: "",
        name: "",
        orderNo: "",
        pid: "2000",
        sfsc: ""
      }).then(res => {
        let optionList = [
          {label: '请选择', value: ''}
        ]
        res.data.forEach((item) => {
          optionList.push({label: item.name, value: item.id})
        })
        this.OptionData.OptionData_stockType = optionList;

      }).catch(err => {
        console.log(err)
      })
    },
    getOptionData_taskTypeNo() {//获取任务类型：字典表
      CommonApi.queryDictData('EN_PATROL_TASK_TYPE').then(res => {
        let optionList = []
        res.data.forEach((item) => {
          optionList.push({label: item.value, value: item.code})
        })
        this.OptionData.OptionData_taskTypeNo = optionList;
      }).catch(err => {
        console.log(err)
      })
    },
    getOptionData_taskTypeTime() {//获取电能表周期
      CommonApi.queryDictData('EN_PATROL_TASK_PERIOD').then(res => {
        let optionList = [
          {label: '请选择', value: ''}
        ]
        res.data.forEach((item) => {
          optionList.push({label: item.value, value: item.value})
        })
        this.OptionData.OptionData_sblxmc = optionList;
      }).catch(err => {
        console.log(err)
      })
    },
    getOptionData_warehouseNo() {//盘点对象：字典表
      CommonApi.queryDictData('EN_EQUIP_SSKF').then(res => {
        let optionList = [
          {label: '', value: ''}
        ]
        res.data.forEach((item) => {
          optionList.push({label: item.value, value: item.code})
        })
        this.OptionData.OptionData_warehouseNo = optionList;
      }).catch(err => {
        console.log(err)
      })
    },
    deptNoChange(value) {
      this.formEvent.patrolRoomNo = ''
      this.formEvent.patrolTargetNames = ''
      this.formEvent.equipAllSelect = false
      this.entityList = []
      this.formEvent.maintainUnitName = '';
      if (value) {
        let arr = this.OptionData.OptionData_deptNo.filter(item => {
          return item.value == value;
        })
        if (arr && arr.length > 0) {
          this.formEvent.maintainUnitName = arr[0].label;
        }
        this.formEvent.maintainTeamName = ''
        this.formEvent.patrolRoomName = ''
        var obj = {
          deptId: value,
          parentId: '',
        }
        listDept(obj).then(res => {
          let optionList = [
            {label: '请选择', value: ''}
          ]
          res.data.forEach((item) => {
            // console.log(item,'item.,,,');
            optionList.push({label: item.deptName, value: item.deptId})
          })
          this.OptionData.OptionData_teamNo = optionList
        }).then(() => {
          preparationTask.getJfByGldw(value).then(res => {
            let optionList = [
              {label: '请选择', value: ''}
            ]
            res.data.forEach((item) => {

              optionList.push({label: item.jfName, value: item.id})
            })
            this.OptionData.OptionData_patrolRoomName = optionList
          })
        })
      }
    },
    teamNoChange(value) {
      this.formEvent.maintainTeamName = ''
      if (value) {
        let arr = this.OptionData.OptionData_teamNo.filter(item => {
          return item.value == value;
        })
        if (arr && arr.length > 0) {
          this.formEvent.maintainTeamName = arr[0].label;

        }
      }
    },
    deptNoChangeRoom(value) {
      this.formEvent.patrolTargetNames = ''
      this.formEvent.equipAllSelect = false
      this.entityList = []
      this.formEvent.patrolRoomName = '';
      if (value) {
        let arr = this.OptionData.OptionData_patrolRoomName.filter(item => {
          return item.value == value;
        })
        if (arr && arr.length > 0) {
          this.formEvent.patrolRoomName = arr[0].label;

        }
      }
    },
    changeSelect(val) {
      console.log(this.formEvent.equipAllSelect)
      if (this.formEvent.maintainUnitNo == '' || this.formEvent.patrolRoomNo == '') {
        this.$message.warning("单位名称或能源站名称不能为空");
        return
      }
      if (val === 1) {
        let params = {
          column: "",
          entity: {

            gldwbm: this.formEvent.maintainUnitNo,//单位
            ssjfbm: this.formEvent.patrolRoomNo,//机房

          },
          order: "",
          pageNo: 1,
          pageSize: 10,
          paramsMap: {}
        }
        preparationTask.getpatorlPage(params).then(res => {
          this.list.data = res.data.records
          this.formEvent.patrolTargetNames = res.data.records[0].sbmc + '等' + res.data.records.length + '个设备'
          this.entityList = []
          this.list.data.forEach((item) => {
            this.entityList.push({
              ccbm: item.ccbm,
              ccrq: item.ccrq,
              cjmc: item.cimc,
              cjr: item.cjr,
              cjtime: item.cjtime,
              gldwbm: item.gldwbm,
              gldwmc: item.gldwmc,
              equipNo: item.sbbm,
              equipName: item.sbmc,
              equipTypeNo: item.sblxbm,
              equipTypeName: item.sblxmc,
              sbzp: item.sbzp,
              sbztOld: item.sbztOld,
              sbztOldmc: item.sbztOldmc,
              equipStatusNo: item.sbztbm,
              equipStatusName: item.sbztmc,
              sfsc: item.sfsc,
              jfNo: item.ssjfbm,
              jfName: item.ssjfmc,
              xh: item.xh,
              yxzt: item.yxzt,
              yxztmc: item.yxztmc
            })
          })
        }).catch(err => {
        })
        this.btnDisabled = true
      } else {
        this.entityList = []
        this.btnDisabled = false
      }

      console.log(this.entityList)
    },
    taskTypeNoChange(value) {
      if (value == 1) {
        this.periodShow = true
      } else {
        this.periodShow = false
        this.formEvent.period = ''
        this.formEvent.periodEndtime = ''
      }
      this.formEvent.patrolTypeName = '';
      if (value) {
        let arr = this.OptionData.OptionData_taskTypeNo.filter(item => {
          return item.value == value;
        })
        if (arr && arr.length > 0) {
          this.formEvent.patrolTypeName = arr[0].label;
        }
        console.log(this.formEvent.patrolTypeName)
      }
    },
    getTaskName(event) {
      /*  if (event.target.value !== undefined) {
         this.formEvent.rwName = event.target.value
       } else {
         this.formEvent.rwName = ''
       }
  */
    },

    setTestTaskName() {
      const deptNo = this.OptionData.OptionData_deptNo.find(d => d.value === this.formEvent.maintainUnitNo) ? this.OptionData.OptionData_deptNo.find(d => d.value === this.formEvent.maintainUnitNo).label : ''
      // const warehouseNo = this.OptionData.OptionData_patrolRoomName.find(d => d.value === this.formEvent.patrolRoomNo) ? this.OptionData.OptionData_patrolRoomName.find(d => d.value === this.formEvent.patrolRoomNo).label : ''
      const taskTypeNo = this.OptionData.OptionData_taskTypeNo.find(d => d.value === this.formEvent.patrolTypeNo) ? this.OptionData.OptionData_taskTypeNo.find(d => d.value === this.formEvent.patrolTypeNo).label : ''
      this.formEvent.taskName = deptNo + taskTypeNo

    },
    handlePlanEndTime(val) {
      if (this.formEvent.patrolTypeNo === '1') {
        if (this.formEvent.period) {
          if (this.formEvent.planStartTime) {
            var today = new Date(this.formEvent.planStartTime)
            var nowTime = today.getTime()
            var ms = 24 * 3600 * 1000 * Number(this.formEvent.period)
            today.setTime(parseInt(nowTime + ms))
            var date1 = Date.parse(new Date(today).toLocaleDateString())
            var date2 = Date.parse(new Date(val).toLocaleDateString())
            if (date1 < date2) {
              this.$message.warning('计划开始时间~计划结束时间的范围应小于等于周期天数')
            }
          } else {
            this.$message.warning('请先选择计划开始时间')
          }
        }
      }
    },
    getTable() {
      preparationTask.getTaskEquipList(this.row.taskNo).then(res => {

        // this.list.data = res.data
        this.entityList = res.data


      }).catch(err => {

      })


    },
    handlePageChange({currentPage, pageSize}) {
      this.list.pageNo = currentPage;
      this.list.pageSize = pageSize;
      this.getTable();
    },
    onSelectEquips(data) {
      this.list.data = data
      this.entityList = []
      this.list.data.forEach((item) => {
        this.entityList.push({
          ccbm: item.ccbm,
          ccrq: item.ccrq,
          cjmc: item.cimc,
          cjr: item.cjr,
          cjtime: item.cjtime,
          gldwbm: item.gldwbm,
          gldwmc: item.gldwmc,
          equipNo: item.sbbm,
          equipName: item.sbmc,
          equipTypeNo: item.sblxbm,
          equipTypeName: item.sblxmc,
          sbzp: item.sbzp,
          sbztOld: item.sbztOld,
          sbztOldmc: item.sbztOldmc,
          equipStatusNo: item.sbztbm,
          equipStatusName: item.sbztmc,
          sfsc: item.sfsc,
          jfNo: item.ssjfbm,
          jfName: item.ssjfmc,
          xh: item.xh,
          yxzt: item.yxzt,
          yxztmc: item.yxztmc
        })
      })


      this.list.data.forEach(item => {
        this.formEvent.patrolTargetNames += ',' + item.sbmc
      })
      this.formEvent.patrolTargetNames = this.formEvent.patrolTargetNames ? this.formEvent.patrolTargetNames.substring(1) : ''
      // this.formEvent.patrolTargetNames = res.data.records[0].sbmc + '等' + res.data.records.length + '个设备'
    },
    handleDelete() {
      const rowArr = this.$refs.selectedEquip.getCheckboxRecords(true)

      // this.entityList = this.entityList.filter(d => rowArr.findIndex(b => b.taskNo === d.taskNo) > 0)
      this.entityList = this.entityList.filter(items => {
        if (!rowArr.includes(items)) return items;
      })
    },
    initData() { 		//初始化表单信�?//

      for (let key in this.formEvent) {
        this.formEvent[key] = this.row[key];
      }
      console.log(this.row)
      // this.formEvent.stockType = this.row.stockType.split(',')
      if (this.row.taskTypeNo == '1') {
        this.periodShow = true
      } else {
        this.periodShow = false
      }
      if (this.childtype == '巡视工单详情' && this.row.patrolTypeNo == '1')
        this.periodShow = true
      this.getTable()
    },

    inventoryClick() {
      if (this.formEvent.maintainUnitNo == '' || this.formEvent.patrolRoomNo == '') {
        this.$message.warning("单位名称或能源站名称不能为空");
        return
      }
      this.$refs.selectEquipment.showDialog(this.formEvent)
    },
    //确定
    handleSubmit() {
      this.formEvent.equipAllSelect = this.formEvent.equipAllSelect ? '1' : '0'
      const api = this.isEdit ? 'updateData' : 'insertData'
      const label = this.isEdit ? '修改' : '新增'

      this.$refs.form.validate((valid) => {
        console.log(valid)
        if (valid) {

          if (this.entityList.length !== 0) {
            this.formEvent.period = this.formEvent.period == '周' ? 'week' : this.formEvent.period == '月' ? 'month' : this.formEvent.period == '季度' ? 'quarter' : this.formEvent.period
            this.formEvent.ptaskStatusName = '未派单'
            this.formEvent.ptaskStatusNo = '0'
            this.formEvent.taskSourceNo = '1'
            const queryParam = Object.assign({}, this.formEvent)

            const params = [{
              ...queryParam,
              equipList: this.entityList
            }]
            preparationTask[api](params).then(res => {
              if (res.code === '200') {
                this.$message.success(label + '成功')
                this.handleCancel()
                this.$emit('onSearch')
              }
            })

            this.handleCancel()
            this.dialogProps.visible = false;
            this.btnDisabled = false

          } else {
            this.$message.warning("巡视设备列表不能为空");

          }

        } else {
          return false;
        }
      });

    },
    //取消
    handleCancel() {
      this.$refs.form.resetFields()
      for (let key in this.formEvent) {
        this.formEvent[key] = "";
      }
      // this.formEvent.stockType = []

      this.row = {}
      this.dialogProps.visible = false;
    },
    handleClose(done) {
      // this.$confirm("确认关闭？")
      // .then((_) => {
      this.handleCancel()
      this.dialogProps.visible = false;
      // })
      // .catch((_) => { });
    },
  },
};
</script>

<style scoped>
.tool-button-container {
  text-align: right;
}

.el-select {
  width: 100% !important
}

.dialog-footer {
  display: inherit;

}

.dialog-footer button {
  margin-right: 10px;
}
</style>
